﻿using Humanizer;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WMS_MAV.DTO.Carrier;
using WMS_MAV.DTO.FinanceType;
using WMS_MAV.DTO.Purchase;
using WMS_MAV.DTO.Purchase.Procurement;
using WMS_MAV.DTO.Warehouse;
using WMS_MAV.DTO.Warehouse.Storage;

namespace WMS_MAV.Controllers
{
    public class PurchaseController : Controller
    {
        private readonly IConfiguration _configuration;
        public PurchaseController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult ClientShow()
        {
            return View();
        }
        public IActionResult UnitShow()
        {
            return View();
        }
        public IActionResult UnitFindShow()
        {
            return View();
        }
        /// <summary>
        /// 财务类别视图
        /// </summary>
        /// <returns></returns>
        public IActionResult FinanceTypeShow()
        {
            return View();
        }
        /// <summary>
        /// 财务记账视图
        /// </summary>
        /// <returns></returns>
        public IActionResult FinanceTotal()
        {
            return View();
        }
        /// <summary>
        /// 财务类别列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetFinanceTypeShow(FinanceTypeShowDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchaseRead/api/FinanceType/GetFinanceTypeList?FinanceTypeName=" + dto.FinanceTypeName;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 添加财务类别
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetFinanceAdd(FinanceTypeAddDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/FinanceType/GetFinanceTypeAdd";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
        /// <summary>
        /// 删除财务类别
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetFinanceDel(FinanceTypeDelDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/FinanceType/GetFinanceTypeDelete";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
        /// <summary>
        /// 批量删除财务类别
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetFinanceDelRange(FinanceRangeDelDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/FinanceType/GetFinanceTypeRangeDelete";
            var list = "{\"ids\":" + dto.Ids + "}";
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 反填财务类别数据
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetFinanceTypeModel(FinanceByIdDto dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchaseRead/api/FinanceType/GetFinanceTypeModel?FinanceTypeId=" + dto.Id;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 修改财务类别
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetFinanceTypeUpd(FinanceTypeUpdDto obj1, string token)
        {

            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/FinanceType/GetFinanceTypeUpdate";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 单位显示
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetUnitShow(int pageIndex, int pageSize, string? unitNo, string? unitName)
        {
            var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0Iiwic2lkIjoiMTg1OTgwNTA4MDc2NTczMDgxNiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvZ3JvdXBzaWQiOiIiLCJqdGkiOiI5MWU1MzVhMy1kZjVlLTQxNGQtODdkMy0zYjE3MmIzNmRhZWEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoi5LqO5a2Q5ra1IiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvdXJpIjoiLyIsImlzcyI6IlJlbmFvYm8yMDA0IiwiYXVkIjoiV2VpZnV3dTIyMDNBIn0.9e371kkhbGOGIALMM210Z0Mhka1BhADJFTKFd8w3AJY";
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = "http://10.223.8.18:8000/purchaseRead/api/Unit/Handle?pageIndex=" + pageIndex + "&pageSize=" + pageSize + "&unitNo=" + unitNo + "&unitName=" + unitName;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 单位添加
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ActionResult> AddUnit(string data)
        {
            var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0Iiwic2lkIjoiMTg1OTgwNTA4MDc2NTczMDgxNiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvZ3JvdXBzaWQiOiIiLCJqdGkiOiI5MWU1MzVhMy1kZjVlLTQxNGQtODdkMy0zYjE3MmIzNmRhZWEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoi5LqO5a2Q5ra1IiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvdXJpIjoiLyIsImlzcyI6IlJlbmFvYm8yMDA0IiwiYXVkIjoiV2VpZnV3dTIyMDNBIn0.9e371kkhbGOGIALMM210Z0Mhka1BhADJFTKFd8w3AJY";
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = "http://10.223.8.18:8000/purchase/api/Unit/Add";
            var response = await client.PostAsync(url, data);
            return Json(response);
        }
        /// <summary>
        /// 单位删除
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ActionResult> GetDeleteUnit(string obj, string token)
        {

            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = "http://10.223.8.18:8000/purchase/api/Unit/DelectUnit";
            var response = await client.PostAsync(url, obj);
            return Json(response);
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetAllDeleteUnit(string token, PurchaseAlldeleteDTO model)
        {
           
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = "http://10.223.8.18:8000/purchase/api/Unit/Handle";
            var list = JsonConvert.SerializeObject(model);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 单位反填
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetFindUnit(int unitId)
        {
            var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0Iiwic2lkIjoiMTg1OTgwNTA4MDc2NTczMDgxNiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvZ3JvdXBzaWQiOiIiLCJqdGkiOiI5MWU1MzVhMy1kZjVlLTQxNGQtODdkMy0zYjE3MmIzNmRhZWEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoi5LqO5a2Q5ra1IiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvdXJpIjoiLyIsImlzcyI6IlJlbmFvYm8yMDA0IiwiYXVkIjoiV2VpZnV3dTIyMDNBIn0.9e371kkhbGOGIALMM210Z0Mhka1BhADJFTKFd8w3AJY";
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = "http://10.223.8.18:8000/purchase/api/Unit/FindUnit?UnitId=" + unitId;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 单位修改
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetUpdateUnit(UnitDTO obj1)
        {
            var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0Iiwic2lkIjoiMTg1OTgwNTA4MDc2NTczMDgxNiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvZ3JvdXBzaWQiOiIiLCJqdGkiOiI5MWU1MzVhMy1kZjVlLTQxNGQtODdkMy0zYjE3MmIzNmRhZWEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoi5LqO5a2Q5ra1IiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvdXJpIjoiLyIsImlzcyI6IlJlbmFvYm8yMDA0IiwiYXVkIjoiV2VpZnV3dTIyMDNBIn0.9e371kkhbGOGIALMM210Z0Mhka1BhADJFTKFd8w3AJY";
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = "http://10.223.8.18:8000/purchase/api/Unit/AllDelectUnit";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        public class UnitDTO
        {
            public int UnitId { get; set; }
            /// <summary>
            /// 单位编号
            /// </summary>
            public string? UnitNo { get; set; }
            /// <summary>
            /// 单位名称
            /// </summary>
            public string? UnitName { get; set; }
            /// <summary>
            /// 备注
            /// </summary>
            public string? UnitRemarks { get; set; }
            /// <summary>
            /// 公司ID
            /// </summary>
            public string? office_id { get; set; }
            /// <summary>
            /// 用户ID
            /// </summary>
            public int? user_id { get; set; }
            /// <summary>
            /// 创建人
            /// </summary>
            public string? CreateName { get; set; }
            /// <summary>
            /// 创建时间
            /// </summary>
            public DateTime? CreateTime { get; set; }
            /// <summary>
            /// 修改人
            /// </summary>
            public string? UpdateName { get; set; }
            /// <summary>
            /// 修改时间
            /// </summary>
            public DateTime? UpdateTime { get; set; }
            /// <summary>
            /// 删除人
            /// </summary>
            public string? DeleteName { get; set; }
            /// <summary>
            /// 删除时间
            /// </summary>
            public DateTime? DeleteTime { get; set; }
            /// <summary>
            /// 是否删除
            /// </summary>
            public bool? IsDelete { get; set; }
        }
        /// <summary>
        /// 单位导出
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="unitNo"></param>
        /// <param name="unitName"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetUnitExcel(int pageIndex, int pageSize, string? unitNo, string? unitName)
        {
            var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0Iiwic2lkIjoiMTg1OTgwNTA4MDc2NTczMDgxNiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvZ3JvdXBzaWQiOiIiLCJqdGkiOiI5MWU1MzVhMy1kZjVlLTQxNGQtODdkMy0zYjE3MmIzNmRhZWEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoi5LqO5a2Q5ra1IiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvdXJpIjoiLyIsImlzcyI6IlJlbmFvYm8yMDA0IiwiYXVkIjoiV2VpZnV3dTIyMDNBIn0.9e371kkhbGOGIALMM210Z0Mhka1BhADJFTKFd8w3AJY";
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = "http://10.223.8.18:8000/purchaseRead/api/Unit/ProductTypeExcel?pageIndex=" + pageIndex + "&pageSize=" + pageSize + "&unitNo=" + unitNo + "&unitName=" + unitName;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 客户显示
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetClientShow(int pageIndex, int pageSize, string? clientNo, string? clientName, string? clientPhone)
        {
            var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0Iiwic2lkIjoiMTg1OTgwNTA4MDc2NTczMDgxNiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvZ3JvdXBzaWQiOiIiLCJqdGkiOiI5MWU1MzVhMy1kZjVlLTQxNGQtODdkMy0zYjE3MmIzNmRhZWEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoi5LqO5a2Q5ra1IiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvdXJpIjoiLyIsImlzcyI6IlJlbmFvYm8yMDA0IiwiYXVkIjoiV2VpZnV3dTIyMDNBIn0.9e371kkhbGOGIALMM210Z0Mhka1BhADJFTKFd8w3AJY";
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = "http://10.223.8.18:8000/purchaseRead/api/Client/ShowClient?pageIndex=" + pageIndex + "&pageSize=" + pageSize + "&clientNo=" + clientNo + "&clientName=" + clientName + "&clientPhone=" + clientPhone;
            var response = await client.GetAsync(url);
            return Json(response);
        }

        /// <summary>
        /// 采购客户类型显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetClientNameShow(string token)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchaseRead/api/Client/GetResult";
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 客户删除
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetDeleteClient(string data)
        {
            var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0Iiwic2lkIjoiMTg1OTgwNTA4MDc2NTczMDgxNiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvZ3JvdXBzaWQiOiIiLCJqdGkiOiI5MWU1MzVhMy1kZjVlLTQxNGQtODdkMy0zYjE3MmIzNmRhZWEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoi5LqO5a2Q5ra1IiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvdXJpIjoiLyIsImlzcyI6IlJlbmFvYm8yMDA0IiwiYXVkIjoiV2VpZnV3dTIyMDNBIn0.9e371kkhbGOGIALMM210Z0Mhka1BhADJFTKFd8w3AJY";
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Client/DelectClientConta";
            var response = await client.PostAsync(url, data);
            return Json(response);
        }
        /// <summary>
        /// 客户联系人反填
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetFindKe(int clientId)
        {
            var token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0Iiwic2lkIjoiMTg1OTgwNTA4MDc2NTczMDgxNiIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvZ3JvdXBzaWQiOiIiLCJqdGkiOiI5MWU1MzVhMy1kZjVlLTQxNGQtODdkMy0zYjE3MmIzNmRhZWEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoi5LqO5a2Q5ra1IiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvdXJpIjoiLyIsImlzcyI6IlJlbmFvYm8yMDA0IiwiYXVkIjoiV2VpZnV3dTIyMDNBIn0.9e371kkhbGOGIALMM210Z0Mhka1BhADJFTKFd8w3AJY";
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Client/FanClienConat?ClientId=" + clientId;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 采购显示
        /// </summary>
        /// <returns></returns>
        public IActionResult ProcurementShow()
        {
            return View();
        }
        /// <summary>
        /// 采购显示
        /// </summary>
        /// <param name="procurement"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetProcurementShow(ProcurementShowDTO procurement)
        {
            HttpClientWrapper client = new HttpClientWrapper(procurement.Token);
            string url = _configuration["Url"] + "purchaseRead/api/Procurements/ShowProcurement?pageIndex=" + procurement.pageIndex + "&pageSize=" + procurement.pageSize + "&procurementNo=" + procurement.procurementNo + "&productNo=" + procurement.productNo + "&productName=" + procurement.productName + "&procurementState=" + procurement.procurementState;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 采购状态下拉显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetProcurementState(string token)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchaseRead/api/Procurements/GetProcurementState";
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 删除采购数据
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetDelectProcurement(DelectProcurementDTO dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/Procurement/DeleteProcurement";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
        /// <summary>
        /// 批量删除采购信息
        /// </summary>
        /// <param name="procurement"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetPlDelectProcurement(string token, DelectRangeProcurementDTO procurement)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Procurement/RangeDeleteProcurement";
            //var para = new { buyProductsId = buyProductsId.buyProductsId };
            string list = JsonConvert.SerializeObject(procurement);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 采购入账
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetProcurementRecorded(RecordedProcurementDTO dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/Procurement/ProcurementRecorded";
            var response = await client.PostAsync(url, dto.buyProductsId);
            return Json(response);
        }
        /// <summary>
        /// 采购添加
        /// </summary>
        /// <returns></returns>
        public IActionResult AddProcurements()
        {
            return View();
        }
        /// <summary>
        /// 添加采购管理
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetAddProcurements(string token, AddProcurementsDTO field)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Procurement/AddProcurement";
            string list = JsonConvert.SerializeObject(field);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 采购入库
        /// </summary>
        /// <returns></returns>
        public IActionResult ProcurementStorage()
        {
            return View();
        }
        /// <summary>
        /// 采购修改
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdProcurement()
        {
            return View();
        }
        /// <summary>
        /// 采购反填
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetFanProcurement(string token, int procurementId)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchaseRead/api/Procurements/FanProcurement?procurementId=" + procurementId;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 修改采购管理
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetUpdateProcurements(string token, AddProcurementsDTO field)
        {
            HttpClientWrapper client = new HttpClientWrapper(token); 
            string url = _configuration["Url"] + "purchase/api/Procurement/UpdateProcurement";
            string list = JsonConvert.SerializeObject(field);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 添加采购退货管理
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetAddReturn(string token, AddReturnDTO field)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Procurement/AddReturn";
            string list = JsonConvert.SerializeObject(field);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 采购退货反填
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetFanReturn(string token, int procurementId)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchaseRead/api/Procurements/FanReturn?procurementId=" + procurementId;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 采购退货显示
        /// </summary>
        /// <returns></returns>
        public IActionResult ReturnShow()
        {
            return View();
        }
        /// <summary>
        /// 采购退货显示
        /// </summary>
        /// <param name="returns"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetReturnShow(ReturnShowDTO returns)
        {
            HttpClientWrapper client = new HttpClientWrapper(returns.Token);
            string url = _configuration["Url"] + "purchaseRead/api/Procurements/ReturnProcurement?pageIndex=" + returns.pageIndex + "&pageSize=" + returns.pageSize + "&returnNo=" + returns.returnNo + "&procurementNo=" + returns.procurementNo + "&productName=" + returns.productName;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 删除采购退货数据
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetDelectReturn(DelectReturnDTO dto)
        {

            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "purchase/api/Procurement/DeleteReturn";
            var response = await client.PostAsync(url, dto.Data);
            return Json(response);
        }
        /// <summary>
        /// 批量删除采购退货
        /// </summary>
        /// <param name="buyProductsId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetDelectRangeReturn(string token, DelectRangeReturnDTO buyProductsId)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Procurement/DeleteRangeReturn";
            //var para = new { buyProductsId = buyProductsId.buyProductsId };
            string list = JsonConvert.SerializeObject(buyProductsId);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
        /// <summary>
        /// 业务员图表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> SalesmanChart(string token)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchaseRead/api/Procurements/AnalysisSalesman";
            var response = await client.GetAsync(url);
            return Json(response);
        }
        public IActionResult SaleShow()
        {
            return View();
        }
        /// <summary>
        /// 销售显示
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SaleShowDo(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchaseRead/api/Sale/SaleShow";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 销售删除
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SaleIsdel(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Sale/SaleOrderDelete";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 销售批量删除
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SaleIsdelAll(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Sale/SaleOrderIsdelAll";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 销售添加
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SaleorderAdd(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Sale/SaleOrderIsdelAll";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 销售添加视图
        /// </summary>
        /// <returns></returns>
        public IActionResult SalesAdd()
        {
            return View();
        }
        /// <summary>
        /// 销售产品显示
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SaleProductFan(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchaseRead/api/Sale/SaleShowFan";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 销售添加
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SaleProductAdd(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Sale/SaleOrderAdd";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 销售修改
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SaleProductUpdate(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Sale/SaleOrderUpdate";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 销售反填
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SaleOrderFan(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/Sale/SaleOrderFan";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 销售修改视图
        /// </summary>
        /// <returns></returns>
        public IActionResult SalesUpdate()
        {
            return View();
        }
        /// <summary>
        /// 销售退货视图
        /// </summary>
        /// <returns></returns>
        public IActionResult SaleReturn()
        {
            return View();
        }
        /// <summary>
        /// 销售退货显示
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SaleReturnShow(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchaseRead/api/SalesReturn/SaleReturnShow";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 销售退货批量删除
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SaleReturnIsdelAll(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/SaleReturn/SaleReturnDelete";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
        /// <summary>
        /// 销售退货反填
        /// </summary>
        /// <param name="model"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> SaleReturnFan(string model, string token)
        {
            HttpClientWrapper httpClientWrapper = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "purchase/api/SaleReturn/SaleReturnFan";
            var response = await httpClientWrapper.PostAsync(url, model);
            return Json(response);
        }
    }
}
